﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class CopyCompanyControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox 新入围年度;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            新入围年度 = (TextBox)FindControl("新入围年度");
            if (!base.Page.IsPostBack) {
                新入围年度.Text = (System.DateTime.Now.Year + 1).ToString();
            }
            Button btnCopy = (Button)FindControl("btnCopy");
            btnCopy.Click += new EventHandler(btnCopy_Click);
        }

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            string rwnd = 新入围年度.Text;
            string tempyear = System.DateTime.Now.Year.ToString();
            if (!string.IsNullOrEmpty(rwnd))
            {
                //if (rwnd != tempyear)
                //{
                    int tt = Convert.ToInt32(_EluZSDataProvider.GetSomeWhere("zs_company", "count(*)", "单位类别='评估机构' and 入围年度='" + rwnd + "'"));
                    if (tt == 0)
                    {
                        _EluZSDataProvider.ComCopy(rwnd);
                        Antu.Utilities.UtilitiesPage.AlertDialog("复制成功！", "setParentValue();");
                    }
                    else {
                        Antu.Utilities.UtilitiesPage.AlertDialog("输入的新入围年度已存在！", "");
                    }
                //}
                //else
                //{
                //    Antu.Utilities.UtilitiesPage.AlertDialog("输入的新入围年度不可为当年年份！", "");
                //}
            }

        }
    }
}


